//
//  PersonalHomePageQuestionAnswerCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "PersonalHomePageQuestionAnswerCell.h"


@interface PersonalHomePageQuestionAnswerCell ()

/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**左边文字*/
@property (nonatomic,strong)UILabel*leftLabel;
/**右边图片*/
@property (nonatomic,strong)UIImageView*rightImage;
/**消息数量*/
@property (nonatomic,strong)UILabel*numberLabel;
/**<#属性#>*/
@property (nonatomic,strong)UILabel*topLabel;


/**<#属性#>*/
@property (nonatomic,strong)UIView*bgView;
/**<#属性#>*/
@property (nonatomic,strong)UIButton*seleBtn;
@end

@implementation PersonalHomePageQuestionAnswerCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)setModel:(PersonalHomePageModel *)model{
    _model = model;
    self.userView.deleButton.hidden = model.isShare;
    self.userView.userName.text = model.userName;
    self.userView.iconImage.image = IMAGE_NAMED(model.userImage);
    self.topLabel.text = model.title;
//    self.leftLabel.text = model.contex;
    self.leftLabel.attributedText = [TitleTool getAttributeStringLineSpacing:4 title:model.contex titleColor:UIColorFromRGB(0x273323) titleFont:BOLDSYSTEMFONT(16)];
    self.rightImage.image = IMAGE_NAMED(model.rightImage);
    self.seleBtn.selected = model.isSelecte;
    self.userView.deleButton.hidden = model.isShare;
}

-(void)reloadCell:(BOOL)isRight{
    self.seleBtn.hidden = !isRight;
    CGFloat left = 0;
    if (isRight) {
        left = 40;
    }
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(left);
    }];

}
-(void)createUI{
    
    self.seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"delete_check_selecet") forState:UIControlStateSelected];
    self.seleBtn.hidden = YES;
    
    kWeakSelf(weakSelf);
    [self.seleBtn addActionHandler:^{
        weakSelf.seleBtn.selected = !weakSelf.seleBtn.selected;
    BlockSafeRun(weakSelf.selecteAction,weakSelf.seleBtn.selected);

    }];
    
    [self addSubview:self.seleBtn];
    
    [self.seleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
    }];

    self.bgView = UIView.new;
    self.bgView.userInteractionEnabled = YES;
    
    [self addSubview:self.bgView];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    self.topLabel = UILabel.new;
    self.topLabel.font = SYSTEMFONT(14);
    self.topLabel.textColor = UIColorFromRGB(0x454F44);
    self.topLabel.text = @"提出问题";
    
    UIView * contenView = [self createContenView];
    
    UIView * numberView = [self createMeseageView];
    
    [self.bgView addSubview:self.userView];
    [self.bgView addSubview:self.topLabel];
    [self.bgView addSubview:contenView];
    [self.bgView addSubview:numberView];

    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];

    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.userView.mas_bottom);
    }];
    
    [contenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.topLabel.mas_bottom).offset(4);
    }];
    [numberView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.bottom.mas_equalTo(-16);
        make.top.mas_equalTo(contenView.mas_bottom).offset(9);
    }];

}
-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        [_userView.deleButton setBackgroundImage:IMAGE_NAMED(@"sangedian") forState:UIControlStateNormal];
        
        [_userView.deleButton addActionHandler:^{
            
        }];    }
    return _userView;
}

-(UILabel*)leftLabel{
    if(!_leftLabel){
        _leftLabel=[UILabel new];
        _leftLabel.textColor = UIColorFromRGB(0x273323);
        _leftLabel.font = SYSTEMFONT(16);
        _leftLabel.numberOfLines = 0;
        _leftLabel.text = @"做烤鸡的时候该怎么做？简单容易上手，老人孩子都喜欢…";
    }
    return _leftLabel;
}
-(UIImageView*)rightImage{
    if(!_rightImage){
        _rightImage=[UIImageView new];
        _rightImage.image = IMAGE_NAMED(@"dynamicDefut");
    }
    return _rightImage;
}

-(UILabel*)numberLabel{
    if(!_numberLabel){
        _numberLabel=[UILabel new];
        _numberLabel.textColor = UIColorFromRGB(0x959E97);
        _numberLabel.font = SYSTEMFONT(12);
        _numberLabel.text = @"658";
    }
    return _numberLabel;
}
-(UIView *)createContenView{
    UIView * view = UIView.new;
    
    ViewBorderRadius(view, 5, 0.5, UIColorFromRGB(0x959E97));
    
    [view addSubview:self.leftLabel];
    [view addSubview:self.rightImage];
    
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.bottom.mas_equalTo(self.rightImage);
        make.right.mas_equalTo(self.rightImage.mas_left).offset(-16);
    }];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(8);
        make.bottom.mas_equalTo(-8);
        make.width.mas_equalTo(72);
        make.height.mas_equalTo(57);
    }];
    
    return view;
}
-(UIView *)createMeseageView{
    UIView * view = UIView.new;
    
    UIButton * imageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [imageBtn setImage:IMAGE_NAMED(@"home_mesae") forState:UIControlStateNormal];
    
    [view addSubview:imageBtn];
    [view addSubview:self.numberLabel];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.mas_equalTo(0);
    }];
    [imageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerY.mas_equalTo(0);
        make.right.mas_equalTo(self.numberLabel.mas_left).offset(-4);
        make.width.height.mas_equalTo(16);
    }];
    
    return view;
}
@end



@interface PersonalHomePageQuestionAnswerOneCell ()

/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**头部文字*/
@property (nonatomic,strong)UILabel*topLabel;
/**底部文字*/
@property (nonatomic,strong)UILabel*bomLabel;
/**回答数量*/
@property (nonatomic,strong)UILabel*numberLabel;


/**<#属性#>*/
@property (nonatomic,strong)UIView*bgView;
/**<#属性#>*/
@property (nonatomic,strong)UIButton*seleBtn;
@end

@implementation PersonalHomePageQuestionAnswerOneCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)setModel:(PersonalHomePageModel *)model{
    _model = model;
    self.userView.userName.text = model.userName;
    self.userView.iconImage.image = IMAGE_NAMED(model.userImage);
//    self.topLabel.text = model.title;
    [TitleTool setDynamicTitle:model.title Label:self.topLabel];
    
//    self.bomLabel.text = model.contex;
    self.bomLabel.attributedText = [TitleTool getAttributeStringLineSpacing:4 title:model.contex titleColor:UIColorFromRGB(0x273323) titleFont:SYSTEMFONT(14)];
    self.numberLabel.text = [NSString stringWithFormat:@"%@回答",model.answerNum];
    self.userView.deleButton.hidden = model.isShare;
}
-(void)reloadCell:(BOOL)isRight{
    self.seleBtn.hidden = !isRight;
    CGFloat left = 0;
    if (isRight) {
        left = 40;
    }
    [self.bgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(left);
    }];

}
-(void)createUI{
    
    self.seleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"me_check_pay_type_defut") forState:UIControlStateNormal];
    [self.seleBtn setBackgroundImage:IMAGE_NAMED(@"delete_check_selecet") forState:UIControlStateSelected];
    self.seleBtn.hidden = YES;
    
    kWeakSelf(weakSelf);
    [self.seleBtn addActionHandler:^{
        weakSelf.seleBtn.selected = !weakSelf.seleBtn.selected;
    BlockSafeRun(weakSelf.selecteAction,weakSelf.seleBtn.selected);

    }];
    
    [self addSubview:self.seleBtn];
    
    [self.seleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
    }];

    self.bgView = UIView.new;
    self.bgView.userInteractionEnabled = YES;
    
    [self addSubview:self.bgView];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
    }];
    
    self.topLabel = UILabel.new;
    self.topLabel.font = BOLDSYSTEMFONT(18);
    self.topLabel.textColor = UIColorFromRGB(0x273323);
    self.topLabel.text = @"提出问题";
    self.topLabel.numberOfLines = 0;
    
    [self.bgView addSubview:self.userView];
    [self.bgView addSubview:self.topLabel];
    [self.bgView addSubview:self.bomLabel];
    [self.bgView addSubview:self.numberLabel];

    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];

    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.userView.mas_bottom);
        make.right.mas_equalTo(-16);
    }];
    
    [self.bomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.topLabel.mas_bottom).offset(4);
    }];
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-16);
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.bomLabel.mas_bottom).offset(9);
    }];

}
-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        [_userView.deleButton setBackgroundImage:IMAGE_NAMED(@"sangedian") forState:UIControlStateNormal];
        
        [_userView.deleButton addActionHandler:^{
            
        }];    }
    return _userView;
}

-(UILabel*)bomLabel{
    if(!_bomLabel){
        _bomLabel=[UILabel new];
        _bomLabel.textColor = UIColorFromRGB(0x273323);
        _bomLabel.font = SYSTEMFONT(14);
        _bomLabel.numberOfLines = 0;
        _bomLabel.text = @"做烤鸡的时候该怎么做？简单容易上手，老人孩子都喜欢…";
    }
    return _bomLabel;
}

-(UILabel*)numberLabel{
    if(!_numberLabel){
        _numberLabel=[UILabel new];
        _numberLabel.textColor = UIColorFromRGB(0x959E97);
        _numberLabel.font = SYSTEMFONT(12);
        _numberLabel.text = @"658";
    }
    return _numberLabel;
}

@end
